﻿using KalevaAalto.DataPart.Excel.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using KalevaAalto.DataPart.Models;
using System.Configuration;
using System.Security.Cryptography.Pkcs;

namespace KalevaAalto.DataPart.Excel.Base
{
    public abstract class BaseWorksheet
    {
        private BaseWorksheets _worksheets;
        public BaseWorksheet(BaseWorksheets worksheets)
        { 
            _worksheets = worksheets; 
        }

        
        public abstract BaseRange Cells { get; }

        public abstract IStyle Sytle { get; }

        public abstract string Name { get; set; }


        public BaseRange? this[CellPos cellPos] => Cells[cellPos];
        public BaseRange? this[int row, int column] => this[new CellPos(row, column)];

        public BaseRange? this[RangePos rangePos] => Cells[rangePos];
        public BaseRange? this[int startRow, int startColumn, int endRow, int endColumn] => this[new RangePos(startRow, startColumn, endRow, endColumn)];

        public BaseRange? this[string address]
        {
            get
            {
                if (RangePos.AddressRegex.IsMatch(address))
                {
                    return this[new RangePos(address)];
                }
                else
                {
                    return this[new CellPos(address)];
                }
            }
        }
        


        public BaseWorkbook Workbook => _worksheets.Workbook;
        public BaseWorksheets Worksheets => _worksheets;
        public DataTable DataTable => Cells.GetDataTable(Name);


        public abstract BaseRange Range { get; }


        public abstract BaseView View { get; }
        

        public virtual void Test()
        {
            throw new NotImplementedException();
        }
        public virtual Task TestAsync()
        {
            throw new NotImplementedException();
        }

    }
}
